// H5广告配置文件

import { AdPlatform } from '@/utils/h5AdAdapter.js'

/**
 * H5广告平台配置
 */
export const H5_AD_CONFIG = {
  // 默认广告平台
  defaultPlatform: process.env.VUE_APP_AD_PLATFORM || AdPlatform.GDT,
  
  // 广告平台配置
  platforms: {
    [AdPlatform.GDT]: {
      name: '腾讯广点通',
      appId: process.env.VUE_APP_GDT_APP_ID || 'your-gdt-app-id',
      sdkUrl: 'https://qzonestyle.gtimg.cn/qzone/biz/gdt/lib/alloyad/alloyad.js',
      adUnits: {
        rewardedVideo: process.env.VUE_APP_GDT_REWARDED_ID || 'your-rewarded-video-id',
        banner: process.env.VUE_APP_GDT_BANNER_ID || 'your-banner-id',
        interstitial: process.env.VUE_APP_GDT_INTERSTITIAL_ID || 'your-interstitial-id'
      },
      // 广告配置
      settings: {
        rewardedVideo: {
          autoLoad: true,
          retryCount: 3,
          retryInterval: 1000
        },
        banner: {
          autoRefresh: true,
          refreshInterval: 30000,
          width: 320,
          height: 50
        }
      }
    },
    
    [AdPlatform.BAIDU]: {
      name: '百度联盟',
      appId: process.env.VUE_APP_BAIDU_APP_ID || 'your-baidu-app-id',
      sdkUrl: 'https://cpro.baidustatic.com/cpro/ui/c.js',
      adUnits: {
        rewardedVideo: process.env.VUE_APP_BAIDU_REWARDED_ID || 'your-rewarded-video-id',
        banner: process.env.VUE_APP_BAIDU_BANNER_ID || 'your-banner-id',
        interstitial: process.env.VUE_APP_BAIDU_INTERSTITIAL_ID || 'your-interstitial-id'
      },
      settings: {
        rewardedVideo: {
          autoLoad: true,
          retryCount: 3,
          retryInterval: 1000
        },
        banner: {
          autoRefresh: true,
          refreshInterval: 30000,
          width: 320,
          height: 50
        }
      }
    },
    
    [AdPlatform.BYTEDANCE]: {
      name: '字节跳动穿山甲',
      appId: process.env.VUE_APP_BYTEDANCE_APP_ID || 'your-bytedance-app-id',
      sdkUrl: 'https://sf16-fe-tos-sg.i18n.pstatp.com/obj/ad-pattern-sg/renderer/package_sg.js',
      adUnits: {
        rewardedVideo: process.env.VUE_APP_BYTEDANCE_REWARDED_ID || 'your-rewarded-video-id',
        banner: process.env.VUE_APP_BYTEDANCE_BANNER_ID || 'your-banner-id',
        interstitial: process.env.VUE_APP_BYTEDANCE_INTERSTITIAL_ID || 'your-interstitial-id'
      },
      settings: {
        rewardedVideo: {
          autoLoad: true,
          retryCount: 3,
          retryInterval: 1000
        },
        banner: {
          autoRefresh: true,
          refreshInterval: 30000,
          width: 320,
          height: 50
        }
      }
    }
  },
  
  // 全局设置
  global: {
    // 广告加载超时时间（毫秒）
    loadTimeout: 10000,
    
    // 广告显示超时时间（毫秒）
    showTimeout: 5000,
    
    // 是否启用调试模式
    debug: process.env.NODE_ENV === 'development',
    
    // 错误重试次数
    maxRetryCount: 3,
    
    // 重试间隔（毫秒）
    retryInterval: 1000,
    
    // 是否自动预加载广告
    autoPreload: true,
    
    // 预加载延迟时间（毫秒）
    preloadDelay: 2000
  }
}

/**
 * 获取广告平台配置
 * @param {string} platform - 广告平台
 * @returns {Object} 平台配置
 */
export function getAdPlatformConfig(platform) {
  return H5_AD_CONFIG.platforms[platform] || null
}

/**
 * 获取当前使用的广告平台
 * @returns {string} 广告平台
 */
export function getCurrentAdPlatform() {
  return H5_AD_CONFIG.defaultPlatform
}

/**
 * 检查广告平台是否支持
 * @param {string} platform - 广告平台
 * @returns {boolean} 是否支持
 */
export function isAdPlatformSupported(platform) {
  return platform in H5_AD_CONFIG.platforms
}

/**
 * 获取广告单元ID
 * @param {string} platform - 广告平台
 * @param {string} adType - 广告类型
 * @returns {string} 广告单元ID
 */
export function getAdUnitId(platform, adType) {
  const config = getAdPlatformConfig(platform)
  return config && config.adUnits && config.adUnits[adType] || null
}

/**
 * 获取广告设置
 * @param {string} platform - 广告平台
 * @param {string} adType - 广告类型
 * @returns {Object} 广告设置
 */
export function getAdSettings(platform, adType) {
  const config = getAdPlatformConfig(platform)
  return config && config.settings && config.settings[adType] || {}
}

export default H5_AD_CONFIG